package org.tc.product.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tc.product.entity.Stocked;
import org.tc.product.mapper.StockedMapper;
import org.tc.product.service.StockedService;
import org.tc.product.util.PageHelper;

import java.util.Date;
import java.util.List;

@Service
@RestController
public class StockedServiceImpl implements StockedService {

    @Autowired
    private StockedMapper stockedMapper;

    @Override
    public PageHelper<Stocked> selectAllStocked(int pageNo, int pageSize, Integer storeid) {
        PageHelper<Stocked> pageHelper = new PageHelper<>();
        pageHelper.setPageNo(pageNo);
        pageHelper.setPageSize(pageSize);
        List<Stocked> slist = stockedMapper.selectAll(pageHelper.getFirstResult(), pageHelper.getPageSize(), storeid);
        pageHelper.setData(slist);
        int sumCount = stockedMapper.getStockCount(storeid);
        int pageCount = sumCount % pageSize == 0 ? sumCount / pageSize : sumCount / pageSize + 1;
        pageHelper.setPageCount(sumCount);
        return pageHelper;
    }

    @Override
    public int updStock(@RequestBody Stocked stocked) {
        return stockedMapper.updStock(stocked);
    }

    @Override
    public int insertStocked(@RequestBody Stocked record) {
        record.setNewtime(new Date());
        int count = stockedMapper.insertStocked(record);
        return count;
    }

    @Override
    public int updStockBec(@RequestBody Stocked stocked) {
        int count = stockedMapper.updStockBec(stocked);
        return count;
    }
}
